/**
 * 登陆界面的js
 * 
 */
$(function(){
	var pathName=window.document.location.pathname;
	var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);//获取项目名
	$("#submitLogin").click(function(){
		submitForm();
	});
	$("#login").bind('keyup',function(event){
		if (event.keyCode == "13") {
			submitForm();
		}
	});
	
	function submitForm(){
		username = $("#username").val();
		password = $("#password").val();
		if (null == username || "" == username || null == password || "" == password) {
			Ext.Msg.alert("登陆失败","用户名或者密码不能为空"); 
			return false;
		}
		
		Ext.Ajax.request({
			url:projectName+"/ajaxVildUser.do",
			mehtod:'POST',
			params:{
				"username":username,
				"password":password
			},
			success : function(response, options) {
				var result = JSON.parse(response.responseText);
				if (result.flag == "false") {
					Ext.Msg.alert('登陆失败', '原因如下：' +result.msg);
					return false;
				}  else if (result.flag == "true" && null != result.msg && "" != result.msg) {
					Ext.Msg.alert('登陆失败', '原因如下：' +result.msg,3000);
					return false;
				} else {
					$("#submitForm").submit();
				}
			},
			failure : function(response, options) {
				var reason = JSON.parse(response.responseText);
				Ext.Msg.alert('提示', '原因如下：' +reason);
				return false;
			}
			
		});
	}
});